home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / private / pdcgetsc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  24.6 KB  |  1,181 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21. #ifdef UNIX
  22. #include <defs.h>
  23. #include <term.h>
  24. #endif
  25.  
  26. #ifdef PDCDEBUG
  27. char *rcsid_PDCgetsc  = "$Id$";
  28. #endif
  29.  
  30. /*man-start*********************************************************************
  31.  
  32.   PDC_get_cursor_pos()    - return current cursor position
  33.  
  34.   PDCurses Description:
  35.      This is a private PDCurses function
  36.  
  37.      Gets the cursor position in video page 0.  'row' and 'column'
  38.      are the cursor address.  At this time, there is no support for
  39.      use of multiple screen pages.
  40.  
  41.   PDCurses Return Value:
  42.      This routine will return OK upon success and otherwise ERR will be
  43.      returned.
  44.  
  45.   PDCurses Errors:
  46.      There are no defined errors for this routine.
  47.  
  48.   Portability:
  49.      PDCurses    int    PDC_get_cursor_pos( int* row, int* col );
  50.  
  51. **man-end**********************************************************************/
  52.  
  53. int    PDC_get_cursor_pos(int *row, int *col)
  54. {
  55. #ifdef PDCDEBUG
  56.     if (trace_on) PDC_debug("PDC_get_cursor_pos() - called\n");
  57. #endif
  58.  
  59. #ifdef    FLEXOS
  60.     retcode = s_get(T_VIRCON, 0L, (char *) &vir, (long) sizeof(vir));
  61.     if (retcode < 0L)
  62.         return( ERR );
  63.     *row = vir.vc_cursor.pos_row;
  64.     *col = vir.vc_cursor.pos_col;
  65.     return( OK );
  66. #endif
  67.  
  68. #ifdef    DOS
  69.     regs.h.ah = 0x03;
  70.     regs.h.bh = _cursvar.video_page;
  71.     int86(0x10, ®s, ®s);
  72.     *row = regs.h.dh;
  73.     *col = regs.h.dl;
  74.     return( OK );
  75. #endif
  76.  
  77. #ifdef    OS2
  78. # ifdef EMXVIDEO
  79.     v_getxy (col, row);
  80. # else
  81.     VioGetCurPos((PUSHORT)row,(PUSHORT)col,0);
  82. # endif
  83.     return( OK );
  84. #endif
  85.  
  86. #ifdef UNIX
  87. /* INCOMPLETE */
  88. #endif
  89. }
  90.  
  91. /*man-start*********************************************************************
  92.  
  93.   PDC_get_cur_col()    - get current column position of cursor
  94.  
  95.   PDCurses Description:
  96.      This is a private PDCurses function
  97.  
  98.      This routine returns the current column position of the cursor on
  99.      screen.
  100.  
  101.   PDCurses Return Value:
  102.      This routine returns the current column position of the cursor. No
  103.      error is returned.
  104.  
  105.   PDCurses Errors:
  106.      There are no defined errors for this routine.
  107.  
  108.   Portability:
  109.      PDCurses    int    PDC_get_cur_col( void );
  110.  
  111. **man-end**********************************************************************/
  112.  
  113. int    PDC_get_cur_col(void)
  114. {
  115. #ifdef    OS2
  116. # ifdef EMXVIDEO
  117.     int curCol=0, curRow=0;
  118. # else
  119.     USHORT curCol=0, curRow=0;
  120. # endif
  121. #endif
  122.  
  123. #ifdef PDCDEBUG
  124.     if (trace_on) PDC_debug("PDC_get_cur_col() - called\n");
  125. #endif
  126.  
  127. #ifdef    FLEXOS
  128.     retcode = s_get(T_VIRCON, 1L, (char *) &vir, (long) sizeof(vir));
  129.     return( (retcode < 0L) ? ERR : vir.vc_cursor.pos_col );
  130. #endif
  131.  
  132. #ifdef    DOS
  133. # ifdef WATCOMC
  134.     regs.w.ax = 0x0003;
  135. # else
  136.     regs.x.ax = 0x0003;
  137. # endif
  138.     regs.h.bh = _cursvar.video_page;
  139.     int86(0x10, ®s, ®s);
  140.     return((int) regs.h.dl);
  141. #endif
  142.  
  143. #ifdef    OS2
  144.     /* find the current cursor position */
  145. # ifdef EMXVIDEO
  146.     v_getxy (&curCol, &curRow);
  147. # else
  148.     VioGetCurPos ((PUSHORT) &curRow, (PUSHORT) &curCol, 0);
  149. # endif
  150.     return (curCol);
  151. #endif
  152.  
  153. #ifdef UNIX
  154. /* INCOMPLETE */
  155. #endif
  156. }
  157.  
  158. /*man-start*********************************************************************
  159.  
  160.   PDC_get_cur_row()    - get current row position of cursor
  161.  
  162.   PDCurses Description:
  163.      This is a private PDCurses function
  164.  
  165.      This routine returns the current row position of the cursor on
  166.      screen.
  167.  
  168.   PDCurses Return Value:
  169.      This routine returns the current row position of the cursor. No
  170.      error is returned.
  171.  
  172.   PDCurses Errors:
  173.      There are no defined errors for this routine.
  174.  
  175.   Portability:
  176.      PDCurses    int    PDC_get_cur_row( void );
  177.  
  178. **man-end**********************************************************************/
  179.  
  180. int    PDC_get_cur_row(void)
  181. {
  182. #ifdef    OS2
  183. # ifdef  EMXVIDEO
  184.     int curCol=0, curRow=0;
  185. # else
  186.     USHORT curCol=0, curRow=0;
  187. # endif
  188. #endif
  189.  
  190. #ifdef PDCDEBUG
  191.     if (trace_on) PDC_debug("PDC_get_cur_row() - called\n");
  192. #endif
  193.  
  194. #ifdef    FLEXOS
  195.     retcode = s_get(T_VIRCON, 1L, (char *) &vir, (long) sizeof(vir));
  196.     return( (retcode < 0L) ? ERR : vir.vc_cursor.pos_col );
  197. #endif
  198.  
  199. #ifdef    DOS
  200. # ifdef WATCOMC
  201.     regs.w.ax = 0x0003;
  202. # else
  203.     regs.x.ax = 0x0003;
  204. # endif
  205.     regs.h.bh = _cursvar.video_page;
  206.     int86(0x10, ®s, ®s);
  207.     return ((int) regs.h.dh);
  208. #endif
  209.  
  210. #ifdef    OS2
  211.     /* find the current cursor position */
  212. # ifdef EMXVIDEO
  213.     v_getxy (&curCol, &curRow);
  214. # else
  215.     VioGetCurPos ((PUSHORT) &curRow, (PUSHORT) &curCol, 0);
  216. # endif
  217.     return (curRow);
  218. #endif
  219.  
  220. #ifdef UNIX
  221. /* INCOMPLETE */
  222. #endif
  223. }
  224.  
  225. /*man-start*********************************************************************
  226.  
  227.   PDC_get_attribute()    - Get attribute at current cursor
  228.  
  229.   PDCurses Description:
  230.      This is a private PDCurses function
  231.  
  232.      Return the current attr at current cursor position on the screen.
  233.  
  234.   PDCurses Return Value:
  235.      This routine will return OK upon success and otherwise ERR will be
  236.      returned.
  237.  
  238.   PDCurses Errors:
  239.      There are no defined errors for this routine.
  240.  
  241.   Portability:
  242.      PDCurses    int    PDC_get_attribute( void );
  243.  
  244. **man-end**********************************************************************/
  245.  
  246. int    PDC_get_attribute(void)
  247. {
  248. #ifdef    OS2
  249. # ifndef EMXVIDEO
  250.     USHORT cellLen = 2;
  251. # endif
  252.     int curRow=0, curCol=0;
  253.     char Cell[4];
  254. #endif
  255.  
  256. #ifdef PDCDEBUG
  257.     if (trace_on) PDC_debug("PDC_get_attribute() - called\n");
  258. #endif
  259.  
  260. #ifdef    FLEXOS
  261.     /* Get and return current attribute.  Force error until fixed. */
  262.     return ((COLOR_CYAN) >> ((sizeof(ch type) / 2) * 8));
  263. #endif
  264.  
  265. #ifdef    DOS
  266. # ifdef WATCOMC
  267.     regs.w.ax = 0x0800;
  268. # else
  269.     regs.x.ax = 0x0800;
  270. # endif
  271.     regs.h.bh = _cursvar.video_page;
  272.     int86(0x10, ®s, ®s);
  273.     return ((int) regs.h.ah);
  274. #endif
  275.  
  276. #ifdef    OS2
  277.     PDC_get_cursor_pos(&curRow, &curCol);
  278. # ifdef EMXVIDEO
  279.     v_getline (Cell, curCol, curRow, 1);
  280. # else
  281.     VioReadCellStr((PCH)&Cell, (PUSHORT)&cellLen, (USHORT)curRow, (USHORT)curCol, 0);
  282. # endif
  283.     return ((int) Cell[1]);
  284. #endif
  285.  
  286. #ifdef UNIX
  287. /* INCOMPLETE */
  288. #endif
  289. }
  290.  
  291. /*man-start*********************************************************************
  292.  
  293.   PDC_get_columns()    - return width of screen/viewport.
  294.  
  295.   PDCurses Description:
  296.      This is a private PDCurses function
  297.  
  298.      This function will return the width of the current screen.
  299.  
  300.   PDCurses Return Value:
  301.      This routine will return OK upon success and otherwise ERR will be
  302.      returned.
  303.  
  304.   PDCurses Errors:
  305.      There are no defined errors for this routine.
  306.  
  307.   Portability:
  308.      PDCurses    int    PDC_get_columns( void );
  309.  
  310. **man-end**********************************************************************/
  311.  
  312. int    PDC_get_columns(void)
  313. {
  314. #ifdef    DOS
  315.     int    cols=0;
  316.     char *env_cols=NULL;
  317. #endif
  318.  
  319. #ifdef    OS2
  320. # ifdef EMXVIDEO
  321.     int rows=0;
  322. # else
  323.     VIOMODEINFO modeInfo;
  324. # endif
  325.     int cols=0;
  326.     char *env_cols=NULL;
  327. #endif
  328.  
  329.  
  330. #ifdef PDCDEBUG
  331.     if (trace_on) PDC_debug("PDC_get_columns() - called\n");
  332. #endif
  333.  
  334. #ifdef    FLEXOS
  335.     return( vir.vc_size.rs_ncols );
  336. #endif
  337.  
  338. #ifdef    DOS
  339. /* use the value from COLS environment variable, if set. MH 10-Jun-92 */
  340. /* and use the minimum of COLS and return from int10h    MH 18-Jun-92 */
  341.     regs.h.ah = 0x0f;
  342.     int86(0x10, ®s, ®s);
  343.     cols = (int)regs.h.ah;
  344.     env_cols = (char *)getenv("COLS");
  345.     if (env_cols != (char *)NULL)
  346.     {
  347.         cols = min(atoi(env_cols),cols);
  348.     }
  349. #ifdef PDCDEBUG
  350.     if (trace_on) PDC_debug("PDC_get_columns() - returned: cols %d\n",cols);
  351. #endif
  352.     return(cols);
  353. #endif
  354.  
  355. #ifdef    OS2
  356. # ifdef EMXVIDEO
  357.     v_dimen (&cols, &rows);
  358. # else
  359.     modeInfo.cb = sizeof(modeInfo);
  360.     VioGetMode(&modeInfo, 0);
  361.     cols = modeInfo.col;
  362. # endif
  363.     env_cols = (char *)getenv("COLS");
  364.     if (env_cols != (char *)NULL)
  365.     {
  366.         cols = min(atoi(env_cols),cols);
  367.     }
  368. #ifdef PDCDEBUG
  369.     if (trace_on) PDC_debug("PDC_get_columns() - returned: cols %d\n",cols);
  370. #endif
  371.     return(cols);
  372. #endif
  373.  
  374. #ifdef UNIX
  375. #ifdef PDCDEBUG
  376.     if (trace_on) PDC_debug("PDC_get_columns() - returned: cols %d\n",columns);
  377. #endif
  378.     return(columns);
  379. #endif
  380.  
  381. #if defined(XCURSES)
  382.     return(XCurses_get_cols());
  383. #endif
  384. }
  385.  
  386. /*man-start*********************************************************************
  387.  
  388.   PDC_get_cursor_mode()    - Get the cursor start and stop scan lines.
  389.  
  390.   PDCurses Description:
  391.      Gets the cursor type to begin in scan line startrow and end in
  392.      scan line endrow.  Both values should be 0-31.
  393.  
  394.   PDCurses Return Value:
  395.      This function returns OK on success and ERR on error.
  396.  
  397.   PDCurses Errors:
  398.      No errors are defined for this function.
  399.  
  400.   Portability:
  401.      PDCurses    int PDC_get_cursor_mode( void );
  402.  
  403. **man-end**********************************************************************/
  404.  
  405. int    PDC_get_cursor_mode(void)
  406. {
  407. #ifdef    DOS
  408.     short    cmode=0;
  409. #endif
  410.  
  411. #ifdef    OS2
  412. # ifdef EMXVIDEO
  413.     int curstart=0, curend=0;
  414. # else
  415.     VIOCURSORINFO cursorInfo;
  416. # endif
  417.     short    cmode=0;
  418. #endif
  419.  
  420. #ifdef PDCDEBUG
  421.     if (trace_on) PDC_debug("PDC_get_cursor_mode() - called\n");
  422. #endif
  423.  
  424. #ifdef    FLEXOS
  425.     /*
  426.      * Under FLEXOS, this routine returns 1 if the cursor is on and 0 if
  427.      * the cursor is off...
  428.      */
  429.     s_getfield(T_VIRCON, VC_MODE, STDOUT, (far BYTE *) & vir,
  430.         sizeof(vir.vc_mode));
  431.  
  432.     if (vir.vc_mode & VCWM_CURSOR)
  433.         return (TRUE);
  434.     else
  435.         return (FALSE);
  436. #endif
  437.  
  438. #ifdef    DOS
  439.     cmode = getdosmemword (0x460);
  440.     return (cmode);
  441. #endif
  442.  
  443. #ifdef    OS2
  444. # ifdef EMXVIDEO
  445.     v_getctype (&curstart, &curend);
  446.     cmode = ((curstart << 8) | (curend));
  447. # else
  448.     VioGetCurType (&cursorInfo, 0);
  449. /* I am not sure about this JGB */
  450.     cmode = ((cursorInfo.yStart << 8) | (cursorInfo.cEnd));
  451. # endif
  452.     return(cmode);
  453. #endif
  454.  
  455. #ifdef UNIX
  456.     return(0);/* this is N/A */
  457. #endif
  458.  
  459. #if defined (XCURSES)
  460.     return(0);/* this is N/A */
  461. #endif
  462. }
  463.  
  464. /*man-start*********************************************************************
  465.  
  466.   PDC_get_font()    - Get the current font size
  467.  
  468.   PDCurses Description:
  469.      This is a private PDCurses routine.
  470.  
  471.      This function returns the current font size.  This function only
  472.      works if the #define FAST_VIDEO is true.
  473.  
  474.   PDCurses Return Value:
  475.      This function returns OK on success and ERR on error.
  476.  
  477.   PDCurses Errors:
  478.      An ERR will be returned if FAST_VIDEO is not true.
  479.  
  480.   Portability:
  481.      PDCurses    int PDC_get_font( void );
  482.  
  483. **man-end**********************************************************************/
  484.  
  485. int    PDC_get_font(void)
  486. {
  487. #if    defined (DOS) && defined (FAST_VIDEO)
  488.     int    retval=0;
  489. #endif
  490.  
  491. #ifdef OS2
  492. # ifdef EMXVIDEO
  493.     int    retval=0;
  494. # else
  495.     VIOMODEINFO modeInfo={0};
  496. # endif
  497. #endif
  498.  
  499. #ifdef PDCDEBUG
  500.     if (trace_on) PDC_debug("PDC_get_font() - called\n");
  501. #endif
  502.  
  503. #if    defined (DOS) && defined (FAST_VIDEO)
  504.     retval = getdosmemword (0x485);
  505.     if ((retval == 0) && (_cursvar.adapter == _MDS_GENIUS))
  506.     {
  507.         retval = _FONT15; /* Assume the MDS Genius is in 66 line mode. */
  508.     }
  509.     switch (_cursvar.adapter)
  510.     {
  511.     case _MDA:
  512.             retval = 10; /* POINTS is not certain on MDA/Hercules */
  513.             break;
  514.     case _EGACOLOR:
  515.     case _EGAMONO:
  516.         switch (retval)
  517.         {
  518.         case _FONT8:
  519.         case _FONT14:
  520.             break;
  521.         default:
  522.             retval = _FONT14;
  523.         }
  524.         break;
  525.  
  526.     case _VGACOLOR:
  527.     case _VGAMONO:
  528.         switch (retval)
  529.         {
  530.         case _FONT8:
  531.         case _FONT14:
  532.         case _FONT16:
  533.             break;
  534.         default:
  535.             break;
  536.         }
  537.         break;
  538.     default:
  539.         break;
  540.     }
  541.     return( retval );
  542. #endif
  543.  
  544. #ifdef OS2
  545. # ifdef EMXVIDEO
  546.     retval = v_hardware();
  547.     return (retval == V_MONOCHROME) ? 14 : (retval == V_COLOR_8) ? 8 : 12;
  548. # else
  549.     modeInfo.cb = sizeof(modeInfo);
  550.             /* set most parameters of modeInfo */
  551.     VioGetMode(&modeInfo, 0);
  552.     return ( modeInfo.vres / modeInfo.row);
  553. # endif
  554. #endif
  555.  
  556. #ifdef UNIX
  557.     return(0); /* this is N/A */
  558. #endif
  559. }
  560.  
  561. /*man-start*********************************************************************
  562.  
  563.   PDC_get_rows()    - Return number of screen rows.
  564.  
  565.   PDCurses Description:
  566.      This is a private PDCurses routine.
  567.  
  568.      Returns the maximum number of rows supported by the display.
  569.      e.g.  25, 28, 43, 50, 60, 66...
  570.  
  571.   PDCurses Return Value:
  572.      This function returns OK on success and ERR on error.
  573.  
  574.   PDCurses Errors:
  575.      No errors are defined for this function.
  576.  
  577.   Portability:
  578.      PDCurses    int PDC_get_rows( void );
  579.  
  580. **man-end**********************************************************************/
  581.  
  582. int    PDC_get_rows(void)
  583. {
  584. #ifdef    DOS
  585.     char *env_rows=NULL;
  586.     int    rows=0;
  587. #endif
  588.  
  589. #ifdef    OS2
  590. # ifdef EMXVIDEO
  591.     int    cols=0;
  592. # else
  593.     VIOMODEINFO modeInfo={0};
  594. # endif
  595.     int    rows=0;
  596.     char *env_rows=NULL;
  597. #endif
  598.  
  599. #ifdef PDCDEBUG
  600.     if (trace_on) PDC_debug("PDC_get_rows() - called\n");
  601. #endif
  602.  
  603. #ifdef    FLEXOS
  604.         return (vir.vc_size.rs_nrows);
  605. #endif
  606.  
  607. #ifdef    DOS
  608. /* use the value from LINES environment variable, if set. MH 10-Jun-92 */
  609. /* and use the minimum of LINES and *ROWS.                MH 18-Jun-92 */
  610.     rows = getdosmembyte(0x484) + 1;
  611.     env_rows = (char *)getenv("LINES");
  612.     if (env_rows != (char *)NULL)
  613.         rows = min(atoi(env_rows),rows);
  614.  
  615.     if ((rows == 1) && (_cursvar.adapter == _MDS_GENIUS))
  616.         rows = 66;
  617.     if ((rows == 1) && (_cursvar.adapter == _MDA))
  618.         rows = 25;  /* new test MH 10-Jun-92 */
  619.     if (rows == 1)
  620.     {
  621.         rows = _default_lines;    /* Allow pre-setting LINES     */
  622.         _cursvar.direct_video = FALSE;
  623.     }
  624.     switch (_cursvar.adapter)
  625.     {
  626.     case _EGACOLOR:
  627.     case _EGAMONO:
  628.         switch (rows)
  629.         {
  630.         case 25:
  631.         case 43:
  632.             break;
  633.         default:
  634.             rows = 25;
  635.         }
  636.         break;
  637.  
  638.     case _VGACOLOR:
  639.     case _VGAMONO:
  640. /* lets be reasonably flexible with VGAs - they could be Super VGAs */
  641. /* capable of displaying any number of lines. MH 10-Jun-92          */
  642. /*
  643.         switch (rows)
  644.         {
  645.         case 25:
  646.         case 28:
  647.         case 50:
  648.             break;
  649.         default:
  650.             rows = 25;
  651.         }
  652. */
  653.         break;
  654.  
  655.     default:
  656.         rows = 25;
  657.         break;
  658.     }
  659. #ifdef PDCDEBUG
  660.     if (trace_on) PDC_debug("PDC_get_rows() - returned: rows %d\n",rows);
  661. #endif
  662.     return (rows);
  663. #endif
  664.  
  665. #ifdef    OS2
  666. /* use the value from LINES environment variable, if set. MH 10-Jun-92 */
  667. /* and use the minimum of LINES and *ROWS.                MH 18-Jun-92 */
  668. # ifdef EMXVIDEO
  669.     v_dimen (&cols, &rows);
  670. # else
  671.     modeInfo.cb = sizeof(modeInfo);
  672.     VioGetMode(&modeInfo, 0);
  673.     rows = modeInfo.row;
  674. # endif
  675.     env_rows = (char *)getenv("LINES");
  676.     if (env_rows != (char *)NULL)
  677.         rows = min(atoi(env_rows),rows);
  678. #ifdef PDCDEBUG
  679.     if (trace_on) PDC_debug("PDC_get_rows() - returned: rows %d\n",rows);
  680. #endif
  681.     return(rows);
  682. #endif
  683.  
  684. #ifdef UNIX
  685. #ifdef PDCDEBUG
  686.     if (trace_on) PDC_debug("PDC_get_rows() - returned: rows %d\n",lines);
  687. #endif
  688.     return(lines);
  689. #endif
  690.  
  691. #if defined(XCURSES)
  692.     return(XCurses_get_rows());
  693. #endif
  694. }
  695.  
  696. /*man-start*********************************************************************
  697.  
  698.   PDC_get_scrn_mode()    - Return the current BIOS video mode
  699.  
  700.   PDCurses Description:
  701.      This is a private PDCurses routine.
  702.  
  703.  
  704.   PDCurses Return Value:
  705.      Returns the current BIOS Video Mode Number.
  706.  
  707.   PDCurses Errors:
  708.      The FLEXOS version of this routine returns an ERR.
  709.      The UNIX version of this routine returns an ERR.
  710.      The EMXVIDEO version of this routine returns an ERR.
  711.  
  712.   Portability:
  713.      PDCurses    int PDC_get_scrn_mode( void );
  714.  
  715. **man-end**********************************************************************/
  716.  
  717. #if defined( OS2 ) && !defined( EMXVIDEO )
  718. VIOMODEINFO    PDC_get_scrn_mode(void)
  719. #else
  720. int    PDC_get_scrn_mode(void)
  721. #endif
  722. {
  723. #if defined( OS2 ) && !defined( EMXVIDEO )
  724.     VIOMODEINFO vioModeInfo={0};
  725. #endif
  726.  
  727. #ifdef PDCDEBUG
  728.     if (trace_on) PDC_debug("PDC_get_scrn_mode() - called\n");
  729. #endif
  730.  
  731. #ifdef    FLEXOS
  732.     return( ERR );
  733. #endif
  734.  
  735. #ifdef    DOS
  736.     regs.h.ah = 0x0f;
  737.     int86(0x10, ®s, ®s);
  738.     return ((int) regs.h.al);
  739. #endif
  740.  
  741. #ifdef     OS2
  742. # ifdef EMXVIDEO
  743.     return(ERR);
  744. # else
  745.     VioGetMode (&vioModeInfo, 0);
  746.     return(vioModeInfo);
  747. # endif
  748. #endif
  749.  
  750. #ifdef UNIX
  751.     return(ERR); /* this is N/A */
  752. #endif
  753. }
  754.  
  755. /*man-start*********************************************************************
  756.  
  757.   PDC_query_adapter_type()    - Determine PC video adapter type
  758.  
  759.   PDCurses Description:
  760.      This is a private PDCurses routine.
  761.  
  762.      Thanks to Jeff Duntemann, K16RA for providing the impetus
  763.      (through the Dr. Dobbs Journal, March 1989 issue) for getting
  764.      the routines below merged into Bjorn Larsson's PDCurses 1.3...
  765.          -- frotz@dri.com    900730
  766.  
  767.   PDCurses Return Value:
  768.      This function returns a macro identifier indicating the adapter
  769.      type.  See the list of adapter types in CURSPRIV.H.
  770.  
  771.   PDCurses Errors:
  772.      No errors are defined for this function.
  773.  
  774.   Portability:
  775.      PDCurses    int PDC_query_adapter_type( void );
  776.  
  777. **man-end**********************************************************************/
  778.  
  779. #if defined( OS2 ) && !defined( EMXVIDEO )
  780. VIOCONFIGINFO    PDC_query_adapter_type(void)
  781. #else
  782. int    PDC_query_adapter_type(void)
  783. #endif
  784. {
  785.     int    retval = _NONE;
  786.  
  787. #ifdef    DOS
  788.         /* thanks to paganini@ax.apc.org for the GO32 fix */
  789. #  if defined(GO32) && defined(NOW_WORKS)
  790. #    include <dpmi.h>
  791.     _go32_dpmi_registers dpmi_regs;
  792. #  endif
  793.     int    equip;
  794.     struct SREGS segs;
  795.     short video_base = getdosmemword (0x463);
  796. #endif
  797.  
  798. #if defined( OS2 ) && !defined( EMXVIDEO )
  799.     VIOCONFIGINFO configInfo={0};
  800. #endif
  801.  
  802. #ifdef PDCDEBUG
  803.     if (trace_on) PDC_debug("PDC_query_adapter_type() - called\n");
  804. #endif
  805.  
  806. #ifdef    FLEXOS
  807.     return (_FLEXOS);
  808. #endif
  809.  
  810. #ifdef    DOS
  811.     /*
  812.      * Attempt to call VGA Identify Adapter Function...
  813.      */
  814.     regs.h.ah = 0x1a;
  815.     regs.h.al = 0;
  816.     int86(0x10, ®s, ®s);
  817.     if ((regs.h.al == 0x1a) && (retval == _NONE))
  818.     {
  819.         /*
  820.          * We know that the PS/2 video BIOS is alive and well.
  821.          */
  822.         switch (regs.h.al)
  823.         {
  824.         case 0:
  825.             retval = _NONE;
  826.             break;
  827.         case 1:
  828.             retval = _MDA;
  829.             break;
  830.         case 2:
  831.             retval = _CGA;
  832.             break;
  833.         case 4:
  834.             retval = _EGACOLOR;
  835.             _cursvar.sizeable = TRUE;
  836.             break;
  837.         case 5:
  838.             retval = _EGAMONO;
  839.             break;
  840.         case 26:
  841.             retval = _VGACOLOR;    /* ...alt. VGA BIOS... */
  842.         case 7:
  843.             retval = _VGACOLOR;
  844.             _cursvar.sizeable = TRUE;
  845.             break;
  846.         case 8:
  847.             retval = _VGAMONO;
  848.             break;
  849.         case 10:
  850.         case 13:
  851.             retval = _MCGACOLOR;
  852.             break;
  853.         case 12:
  854.             retval = _MCGAMONO;
  855.             break;
  856.         default:
  857.             retval = _CGA;
  858.             break;
  859.         }
  860.     }
  861.     else
  862.     {
  863.         /*
  864.          * No VGA BIOS, check for an EGA BIOS by selecting an
  865.          * Alternate Function Service...
  866.          *
  867.          * bx == 0x0010     -->  return EGA information
  868.          */
  869.         regs.h.ah = 0x12;
  870. # ifdef WATCOMC
  871.         regs.w.bx = 0x10;
  872. # else
  873.         regs.x.bx = 0x10;
  874. # endif
  875.         int86(0x10, ®s, ®s);
  876.         if ((regs.h.bl != 0x10) && (retval == _NONE))
  877.         {
  878.             /*
  879.              * An EGA BIOS exists...
  880.              */
  881.             regs.h.ah = 0x12;
  882.             regs.h.bl = 0x10;
  883.             int86(0x10, ®s, ®s);
  884.             if (regs.h.bh == 0)
  885.                 retval = _EGACOLOR;
  886.             else
  887.                 retval = _EGAMONO;
  888.         }
  889.         else
  890.         if (retval == _NONE)
  891.         {
  892.             /*
  893.              * Now we know we only have CGA or MDA...
  894.              */
  895.             int86(0x11, ®s, ®s);
  896.             equip = (regs.h.al & 0x30) >> 4;
  897.             switch (equip)
  898.             {
  899.             case 1:
  900.             case 2:
  901.                 retval = _CGA;
  902.                 break;
  903.             case 3:
  904.                 retval = _MDA;
  905.                 break;
  906.             default:
  907.                 retval = _NONE;
  908.                 break;
  909.             }
  910.         }
  911.     }
  912.     if (video_base == 0x3d4)
  913.     {
  914.         _cursvar.video_seg = 0xb800;
  915.         switch (retval)
  916.         {
  917.         case _EGAMONO:
  918.             retval = _EGACOLOR;
  919.             break;
  920.         case _VGAMONO:
  921.             retval = _VGACOLOR;
  922.             break;
  923.         default:
  924.             break;
  925.         }
  926.     }
  927.     if (video_base == 0x3b4)
  928.     {
  929.         _cursvar.video_seg = 0xb000;
  930.         switch (retval)
  931.         {
  932.         case _EGACOLOR:
  933.             retval = _EGAMONO;
  934.             break;
  935.         case _VGACOLOR:
  936.             retval = _VGAMONO;
  937.             break;
  938.         default:
  939.             break;
  940.         }
  941.     }
  942.     if ((retval == _NONE)
  943. #ifndef CGA_DIRECT
  944.     ||  (retval == _CGA)
  945. #endif
  946.     )
  947.     {
  948.         _cursvar.direct_video = FALSE;
  949.     }
  950.     if ((unsigned int) _cursvar.video_seg == 0xb000)
  951.         _cursvar.mono = TRUE;
  952.     else
  953.         _cursvar.mono = FALSE;
  954.  
  955.         /* Check for DESQview shadow buffer */
  956.         /* thanks to paganini@ax.apc.org for the GO32 fix */
  957. #if defined(GO32) && defined(NOW_WORKS)
  958.     dpmi_regs.h.ah = 0xfe;
  959.     dpmi_regs.h.al = 0;
  960.     dpmi_regs.x.di = _cursvar.video_ofs;
  961.     dpmi_regs.x.es = _cursvar.video_seg;
  962.     _go32_dpmi_simulate_int(0x10, &dpmi_regs);
  963.     _cursvar.video_ofs = dpmi_regs.x.di;
  964.     _cursvar.video_seg = dpmi_regs.x.es;
  965. #endif
  966.  
  967. #if !defined(GO32) && !defined(WATCOMC)
  968.     regs.h.ah = 0xfe;
  969.     regs.h.al = 0;
  970.     regs.x.di = _cursvar.video_ofs;
  971.     segs.es   = _cursvar.video_seg;
  972.     int86x(0x10, ®s, ®s, &segs);
  973.     _cursvar.video_ofs = regs.x.di;
  974.     _cursvar.video_seg = segs.es;
  975. #endif
  976.  
  977.     if  (!_cursvar.adapter)
  978.         _cursvar.adapter = retval;
  979.     return (PDC_sanity_check(retval));
  980. #endif
  981.  
  982. #ifdef    OS2
  983. # ifdef EMXVIDEO
  984.     _cursvar.adapter = v_hardware();
  985.     if (_cursvar.adapter == V_MONOCHROME)
  986.     {
  987.         _cursvar.mono = TRUE;
  988.         retval = _UNIX_MONO;
  989.     }
  990.     else
  991.     {
  992.         _cursvar.mono = FALSE;
  993.         retval = _UNIX_COLOR;
  994.     }
  995.     _cursvar.sizeable = TRUE;
  996.     _cursvar.bogus_adapter = FALSE;
  997.     return(retval);
  998. # else
  999.     VioGetConfig(0, &configInfo, 0);
  1000.     _cursvar.sizeable = TRUE;
  1001.         return configInfo;
  1002. #  if     0
  1003.     switch (configInfo.adapter)
  1004.     {
  1005.         case 0:
  1006.             retval = _MDA;
  1007.             _cursvar.mono =TRUE;
  1008.             break;
  1009.         case 1:
  1010.             retval = _CGA;
  1011.             _cursvar.mono = FALSE;
  1012.             break;
  1013.         case 2: switch (configInfo.display)
  1014.             {
  1015.                 case 0:
  1016.                 case 3:
  1017.                     retval = _EGAMONO;
  1018.                     _cursvar.mono = TRUE;
  1019.                     break;
  1020.                 case 1:
  1021.                 case 2:
  1022.                 case 4:
  1023.                 case 9:
  1024.                     retval = _EGACOLOR;
  1025.                     _cursvar.mono = FALSE;
  1026.                     break;
  1027.             }
  1028.             break;
  1029.         case 3: switch (configInfo.display)
  1030.             {
  1031.                 case 0:
  1032.                 case 3:
  1033.                     retval = _VGAMONO;
  1034.                     _cursvar.sizeable = TRUE;
  1035.                     _cursvar.mono = TRUE;
  1036.                     break;
  1037.                 case 1:
  1038.                 case 2:
  1039.                 case 4:
  1040.                 case 9:
  1041.                     retval = _VGACOLOR;
  1042.                     _cursvar.sizeable = TRUE;
  1043.                     _cursvar.mono = FALSE;
  1044.                     break;
  1045.             }
  1046.             break;
  1047.         default:
  1048.             retval = _CGA;
  1049.             _cursvar.mono = FALSE;
  1050.             break;
  1051.     }
  1052.     return (PDC_sanity_check(retval));
  1053. #  endif
  1054. # endif
  1055. #endif
  1056.  
  1057. #ifdef UNIX
  1058.     if (set_foreground != NULL && set_background != NULL) /* we have a colour monitor */
  1059.         {
  1060.         _cursvar.mono = FALSE;
  1061.         retval = _UNIX_COLOR;
  1062.         }
  1063.     else
  1064.         {
  1065.         _cursvar.mono = TRUE;
  1066.         retval = _UNIX_MONO;
  1067.         }
  1068.     _cursvar.sizeable = FALSE;
  1069.     _cursvar.bogus_adapter = FALSE;
  1070. return(retval);
  1071. #endif
  1072. }
  1073.  
  1074. /*man-start*********************************************************************
  1075.  
  1076.   PDC_sanity_check() - A video adapter identification sanity check
  1077.  
  1078.   PDCurses Description:
  1079.      This is a private PDCurses routine.
  1080.  
  1081.      This routine will force sane values for various control flags.
  1082.  
  1083.   PDCurses Return Value:
  1084.      This function returns OK on success and ERR on error.
  1085.  
  1086.   PDCurses Errors:
  1087.      No errors are defined for this function.
  1088.  
  1089.   Portability:
  1090.      PDCurses    int PDC_sanity_check( int adapter );
  1091.  
  1092. **man-end**********************************************************************/
  1093.  
  1094. int    PDC_sanity_check(int adapter)
  1095. {
  1096.     int    fontsize = PDC_get_font();
  1097.     int    rows     = PDC_get_rows();
  1098.  
  1099. #ifdef PDCDEBUG
  1100.     if (trace_on) PDC_debug("PDC_sanity_check() - called: Adapter %d\n",adapter);
  1101. #endif
  1102.  
  1103.     switch (adapter)
  1104.     {
  1105.     case _EGACOLOR:
  1106.     case _EGAMONO:
  1107.         switch (rows)
  1108.         {
  1109.         case 25:    break;
  1110.         case 43:    break;
  1111.         default:
  1112.             _cursvar.bogus_adapter = TRUE;
  1113.             break;
  1114.         }
  1115.  
  1116.         switch (fontsize)
  1117.         {
  1118.         case _FONT8:    break;
  1119.         case _FONT14:    break;
  1120.         default:
  1121.             _cursvar.bogus_adapter = TRUE;
  1122.             break;
  1123.         }
  1124.         break;
  1125.  
  1126.     case _VGACOLOR:
  1127.     case _VGAMONO:
  1128.  
  1129. /*                                                                  */
  1130. /* lets be reasonably flexible with VGAs - they could be Super VGAs */
  1131. /* capable of displaying any number of lines. MH 10-Jun-92          */
  1132. /* This also applies to font size.            MH 16-Jun-92          */
  1133. /*
  1134.         switch (rows)
  1135.         {
  1136.         case 25:    break;
  1137.         case 43:    break;
  1138.         case 50:    break;
  1139.         default:
  1140.             _cursvar.bogus_adapter = TRUE;
  1141.             break;
  1142.         }
  1143.  
  1144.         switch (fontsize)
  1145.         {
  1146.         case _FONT8:    break;
  1147.         case _FONT14:    break;
  1148.         case _FONT16:    break;
  1149.         default:
  1150.             _cursvar.bogus_adapter = TRUE;
  1151.             break;
  1152.         }
  1153. */
  1154.         break;
  1155.  
  1156.     case _CGA:
  1157.     case _MDA:
  1158.     case _MCGACOLOR:
  1159.     case _MCGAMONO:
  1160.         switch (rows)
  1161.         {
  1162.         case 25:    break;
  1163.         default:
  1164.             _cursvar.bogus_adapter = TRUE;
  1165.             break;
  1166.         }
  1167.         break;
  1168.  
  1169.     default:
  1170.         _cursvar.bogus_adapter = TRUE;
  1171.         break;
  1172.     }
  1173.     if (_cursvar.bogus_adapter)
  1174.     {
  1175.         _cursvar.sizeable    = FALSE;
  1176.         _cursvar.direct_video    = FALSE;
  1177.     }
  1178.     return (adapter);
  1179. }
  1180.